package com.hhs.storage.controller;


import com.hhs.storage.bean.Car;
import com.hhs.storage.bean.Driver;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.service.CarService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhs
 * @since 2022-12-21
 */
@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private CarService carService;
    @RequestMapping(value = "table")
    public Map<String, Object> getAll(Car car, InputParam inputParam) {
        return carService.getAll(car,inputParam);
    }

    /**
     * 查询车辆出车和异常统计数据
     * @param car
     * @param inputParam
     * @return
     */
    @RequestMapping(value = "countTable")
    public Map<String, Object> countTable(Car car, InputParam inputParam) {
        return carService.countTable(car,inputParam);
    }
    @PostMapping(value = "edit")
    public Map<String, Object> addOrUpdate(Car car, String deleIdStr, MultipartFile[] drivingPermitList){
        return carService.addOrUpdate(car,deleIdStr,drivingPermitList);
    }
    @PostMapping(value = "dele")
    public Map dele(String id) {
        try{
            return carService.dele(id);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseInfo.error("存在关联业务，无法删除");
        }
    }
    @PostMapping(value = "changeState")
    public Map<String, Object> changeState(@RequestParam String id, @RequestParam Integer state){
        return carService.changeState(id,state);
    }
}

